<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta charset="utf-8" />
	<title></title>
	<link href="../css/bootstrap.min.css" rel="stylesheet">
	<link href="../css/bootstrap-select.css" rel="stylesheet">
	<link rel="stylesheet" href="../css/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" href="../css/bootstrap-treeview.min.css">
	<link href="../css/font-awesome.min.css" rel="stylesheet">
	<link href="../css/JyyCommon.css" rel="stylesheet">
	<link href="../css/JyyTable.css" rel="stylesheet">
	<link href="../css/JyyTree.css" rel="stylesheet">
	<link href="../css/JyyMsgBox.css" rel="stylesheet">
	<script type="text/javascript" src="../js/jquery-3.2.1.js"></script>
	<script type="text/javascript" src="../js/jquery.form.min.js"></script> 
	<script type="text/javascript" src="../js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-datetimepicker.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-paginator.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-treeview.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-select.js"></script>
	<script type="text/javascript" src="../js/jyy_modal.js"></script>
	<script type="text/javascript" src="../js/JyyCommon.js"></script>
	<script type="text/javascript" src="../js/JyyTable.js"></script>
	<script type="text/javascript" src="../js/JyyTree.js"></script>
	<script type="text/javascript" src="../js/JyyMsgBox.js"></script>
	<script type="text/javascript" src="../js/JyyLoading.js"></script>
	<script type="text/javascript" src="../js/echarts.js"></script>
	<script type="text/javascript" src="../../utils/CommonUtil.js"></script>
	<style>
	.heidenbt{
		display: none
	}
	.selBtn {
		float:left;
		margin-left:5px;
		margin-right:5px;
		height:30px;
		width:70px;
		background-color:#1890FF;
		border-radius:5px;
		border: 0px;
		color:white;
	}
	.selBtn:hover {
		background-color: #00BFFF;
	}
</style>
	<script type="text/javascript">
		var tree = null;
		var table = null;
		var scheme = null;
		var treeCode = null;
		//var dataCode = '20101';
		var projectId =  '88888888888';
		var dataCode =  '88888888888';
		var begintime = '20300101';
		$(function(){
			//scheme = parent.getSelectScheme();
			//加载树组件
			 projectId =  getQueryString("projectId")||'88888888888';
			 dataCode =  getQueryString("dataCode")||'88888888888';
			 getDatePicker();
		})
		function selectData(){
			
			JyyLoading.start();
			$.when(getTableData(dataCode)).done(function(tableData){
				if(table == null){
					table = JyyTable.init("table", tableData, {position:"absolute",top:"50px",left:"5px",right:"5px",bottom:"0px",overflow:"hidden"}, onTableEvent);
				}else{
					table.refresh(tableData);
				}
				JyyLoading.end();
			});
		}
		function onTreeEvent(event){
			console.log("onTreeEvent");
				$("#table").css("display","block");
				$("#operate").css("display","block");
				$("#iframe").css("display","none");
				//treeCode = data.code;
				setlabel();
				JyyLoading.start();
				$.when(getTableData(dataCode)).done(function(tableData){
					if(table == null){
						table = JyyTable.init("table", tableData, {position:"absolute",top:"50px",left:"5px",right:"5px",bottom:"0px",overflow:"hidden"}, onTableEvent);
					}else{
						table.refresh(tableData);
					}
					JyyLoading.end();
				});
					 
		}
		function getQueryString (name){
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			return r ? unescape(r[2]) : null;
		}
		function setlabel(){
			//$("#daochu").addClass("heidenbt")
			$("#daoru").addClass("heidenbt")
			$("#xinzeng").addClass("heidenbt")
			$("#shanchu").addClass("heidenbt")
			$("#xianshi").addClass("heidenbt")
			$("#searchName").addClass("heidenbt");
		}
		function getDatePicker(){
			$.ajax({
				url: "Sample/selectElectBalanceDate",
				type:'POST',
				cache:false,
				dataType: "json",
				data:JSON.stringify({ projectId : projectId }),
				contentType:"application/json",
	            success:function(data){
	            	if(!data.respData.readOnly){
		    			$("#dateSel").datetimepicker({
		    				format : 'yyyy-mm-dd', // 展现格式
		    				autoclose : true, // 选择日期后关闭
		    				language : 'zh-CN', //显示语言为中文
		    				minView : "2",
		    				startDate : new Date(data.respData.startDate),
		    				endDate : new Date(data.respData.endDate)
		    			});
		    			$("#dateSel").datetimepicker("setDate", new Date(data.respData.startDate));
		            	selectData();
	            	} else {
		    			$("#dateSel").datetimepicker({
		    				format : 'yyyy-mm-dd', // 展现格式
		    				autoclose : true, // 选择日期后关闭
		    				language : 'zh-CN', //显示语言为中文
		    				minView : "2",
		    				startDate : new Date(),
		    				endDate : new Date()-1000*60*60*24
		    			});
						JyyMsgBox.alert({ title:"警告", message:"暂无相关数据",type:"warning"}).on(function (e) {});
	            	}
	            }
			});
		}
		function onTableEvent(type, value){
			console.log("onTableEvent");
			var code = dataCode;
			if(type == "insertBefore"){
				console.log("insertBefore");
				//核查数据正确性
				for(var a = 0 ; a < value[1].length; a++){
					if(table.config.hideCols.indexOf(a) <= -1){
						if(JyyCommon.isEmpty(value[1][a])){
							JyyMsgBox.alert({ title:"警告", message:"["+table.config.data[0][a-1].name+"]不可为空",type:"warning"}).on(function (e) {});
							return false;
						}else if((!JyyCommon.isObject(value[1][a]) && value[1][a].indexOf("请选择")>-1) || value[1][a] == " "){
							JyyMsgBox.alert({ title:"警告", message:"["+table.config.data[0][a-1].name+"]下拉框未做选择",type:"warning"}).on(function (e) {});
							return false;
						}else if(JyyCommon.isObject(value[1][a]) && JyyCommon.isEmpty(value[1][a].name)){
							JyyMsgBox.alert({ title:"警告", message:"["+table.config.data[0][a-1].name+"]不可为空",type:"warning"}).on(function (e) {});
							return false;
						}
					}
				}
				return true;
			} else if(type == "data"){
				JyyLoading.start();
 				 $.ajax({
		            type:"POST",
		            url:"../pv/page/check/"+code,
		            data:{"value":JSON.stringify(value),"projectid":parent.planId},
		      //      contentType:"application/json", 
		            success:function(data){
		            	var pageSize = table.config.page.option.pageSize;
						$.when(getTableData(code, 1, pageSize, $("#term").val())).done(function(tableData){
							table.refresh(tableData);
							JyyLoading.end();
						});
		            }
		        }); 
			} else if(type == "page"){
				console.log("page");
				var val = $("#term").val();
				var code = dataCode;
				JyyLoading.start();
				$.when(getTableData(code, value.currentPage, value.pageSize, val)).done(function(tableData){
					table.refresh(tableData);
					JyyLoading.end();
				});
			}
		}
		//新增按钮
		function addRow(){
			table.addRow();
		}
		//修改按钮
		function updateRow(){
			table.updateRows();
		}
		//取消修改按钮
		function cancelRow(){
			table.cancelRow();
		}
		//删除按钮
		function deleteRow(){
			table.deleteRows();
		}
		//保存按钮
		function saveRow(){
			table.saveRow();
		}
		//下载按钮
		function download(){
			var dateSel =  $('#dateSel').val(); 
			if(JyyCommon.isEmpty(dateSel)){
				JyyMsgBox.alert({ title:"警告", message:"[日期]不可为空",type:"warning"}).on(function (e) {});
				return false;
			}
			dateSel = dateSel.replace('-','');
			dateSel = dateSel.replace('-','');
			const url = localStorage.getItem('baseURL')
			var form = $(`<form id="download" action="${url}pageExcel/downloadExcel/`+ dataCode +'" style="display:none" method="post">');
			var input = $('<input type="hidden" name="projectid">');
		//	var iframe = $('<iframe name="downloadIframe" type="hidden">');
			input.attr("value",projectId);
			form.append(input);
			 input = $('<input type="hidden" name="begintime">');
			input.attr("value",dateSel);
			form.append(input);
		//	iframe.contents().find('body').append(form)
			$("body").append(form);
			formSubmit(document.querySelector('#download'), getFileName());
			form.submit();
			//iframe.remove();
			form.remove();
		}
		//上传按钮
		function upload(){
			var file = document.getElementById("file");
			if(file.value == ""){
				return;
			}
			JyyLoading.start();
			var fileObj = file.files[0];
			var url = "../pv/pageExcel/loadExcel/"+treeCode;

			var form = new FormData();
			form.append("file",fileObj);
			form.append("schemeid",parent.planId);
			var xhr = new XMLHttpRequest();
			xhr.open("post", url, true);
			xhr.send(form);
			xhr.onreadystatechange = function(){
			    if(xhr.readyState === 4 && xhr.status === 200){
					$.when(getTableData(treeCode)).done(function(tableData){
						table.refresh(tableData);
						JyyLoading.end();
					   document.getElementById("file").value=null
					});
			    }
			}

		}
        function getFileName(){
            if(dataCode == 1004703) return "电力平衡统计表";
            if(dataCode == 1004704) return "电量平衡统计表";
            return "未知文件";
        }
		//全量上传事件
		function allDownloads(event){
			if(event.value == ""){
				return;
			}
			JyyLoading.start();
			$("#form1").find("input[name='schemeid']").val(parent.planId);
			$("#form1").ajaxSubmit({
				success : function(data) {
					alert(data);
					location.reload();
				}
			});
		}
		//显示隐藏列按钮
		function colsState(e){
			var i = $(e).find('i');
			if($(i).is('.glyphicon-align-justify')){
				$(i).removeClass('glyphicon-align-justify')
				$(i).addClass('glyphicon-list');
				$(e).html($(e).html().replace("显示隐藏列", "隐藏默认列"));
				table.hideCols(false);
			}else{
				$(i).removeClass('glyphicon-list')
				$(i).addClass('glyphicon-align-justify');
				$(e).html($(e).html().replace("隐藏默认列", "显示隐藏列"));
				table.hideCols(true);
			}
		}
		//查询
		function select(){
			
			selectData();
		}
		//重置
		function reset(){
			
			$("#term").val("");
			
		//	var currentPage = table.config.page.option.currentPage;
			var currentPage = 1;
			var pageSize = table.config.page.option.pageSize;
			
			JyyLoading.start();
			$.when(getTableData(treeCode, currentPage, pageSize, null)).done(function(tableData){
				table.refresh(tableData);
				JyyLoading.end();
			});
		}
		
		function getTreeData(){
			return [
				{code:"200",name:"批量处理",draggable:false,level:1,items:[
					{code:"201",name:"全量导入",isLeaf:true,draggable:false,items:[]},
					{code:"202",name:"全量导出",isLeaf:true,draggable:false,items:[]},
				]},
				/* {
					code:"900",name:"接线图",draggable:false,level:2,
					items:[{code:"901",name:"接线图",isLeaf:true,draggable:false,items:[]}]
				}, */
//				{
//					code:"100",name:"废弃页面",draggable:false,level:1,
//					items:[
//						{code:"101",name:"系统",isLeaf:true,draggable:false,items:[]},
//						{code:"103",name:"水电机组",isLeaf:true,draggable:false,items:[]},
//						{code:"105",name:"水库",isLeaf:true,draggable:false,items:[]},
//						{code:"106",name:"水库来水",isLeaf:true,draggable:false,items:[]},
//						{code:"110",name:"风电备用",isLeaf:true,draggable:false,items:[]},
//						{code:"114",name:"规划电力备用",isLeaf:true,draggable:false,items:[]},
//						{code:"115",name:"灾区信息",isLeaf:true,draggable:false,items:[]},
//						{code:"116",name:"灾区线路包含关系",isLeaf:true,draggable:false,items:[]},
//						{code:"118",name:"区域信息",isLeaf:true,draggable:false,items:[]},
//						{code:"119",name:"区域负荷相关系数",isLeaf:true,draggable:false,items:[]},
//						{code:"120",name:"发电公司",isLeaf:true,draggable:false,items:[]},
//						{code:"121",name:"机组规划类型",isLeaf:true,draggable:false,items:[]},
//						{code:"125",name:"机组指定电量",isLeaf:true,draggable:false,items:[]},
//						{code:"130",name:"待建线路关系",isLeaf:true,draggable:false,items:[]},
//						{code:"131",name:"线路区域",isLeaf:true,draggable:false,items:[]}
//					]
//				},
				{
					code:"300",name:"节点信息",draggable:false,level:1,
					items:[	{code:"117",name:"节点",isLeaf:true,draggable:false,items:[]}]
				},{
					code:"400",name:"机组信息",draggable:false,level:1,
					items:[	{code:"102",name:"机组",isLeaf:true,draggable:false,items:[]},
							{code:"104",name:"水电三段式出力",isLeaf:true,draggable:false,items:[]},
							{code:"123",name:"机组指定出力",isLeaf:true,draggable:false,items:[]},
							{code:"124",name:"机组指定状态",isLeaf:true,draggable:false,items:[]},
							{code:"122",name:"机组报价",isLeaf:true,draggable:false,items:[]}]
				},{
					code:"500",name:"风电信息",draggable:false,level:1,
					items:[	{code:"108",name:"风区信息",isLeaf:true,draggable:false,items:[]},
							{code:"107",name:"风电场",isLeaf:true,draggable:false,items:[]},
							{code:"109",name:"风区之间相关系数",isLeaf:true,draggable:false,items:[]}]
				},{
					code:"600",name:"光伏信息",draggable:false,level:1,
					items:[	{code:"112",name:"光区信息",isLeaf:true,draggable:false,items:[]},
							{code:"111",name:"光伏电站",isLeaf:true,draggable:false,items:[]},
							{code:"113",name:"光区之间相关系数",isLeaf:true,draggable:false,items:[]}]
				},{
					code:"700",name:"线路断面信息",draggable:false,level:1,
					items:[	{code:"128",name:"线路",isLeaf:true,draggable:false,items:[]},
							{code:"126",name:"断面",isLeaf:true,draggable:false,items:[]},
							{code:"129",name:"断面线路包含关系",isLeaf:true,draggable:false,items:[]},
							{code:"127",name:"断面指定出力",isLeaf:true,draggable:false,items:[]}]
				},{
					code:"800",name:"负荷信息",draggable:false,level:1,
					items:[	{code:"132",name:"负荷曲线",isLeaf:true,draggable:false,items:[]},
						{code:"20102",name:"负荷曲线",isLeaf:true,draggable:false,items:[]},
						{code:"20101",name:"负荷曲线",isLeaf:true,draggable:false,items:[]}]
				},{
					code:"900",name:"仿真结果",draggable:false,level:1,
					items:[	{code:"1004101",name:"二氧化硫",isLeaf:true,draggable:false,items:[]},
						{code:"1004102",name:"二氧化碳",isLeaf:true,draggable:false,items:[]},
						{code:"1004103",name:"燃煤",isLeaf:true,draggable:false,items:[]},
						{code:"1004104",name:"烟尘",isLeaf:true,draggable:false,items:[]},
						{code:"1004105",name:"氮氧化合物",isLeaf:true,draggable:false,items:[]},
						{code:"1004106",name:"灰渣",isLeaf:true,draggable:false,items:[]},
						{code:"1004107",name:"碳氢化物",isLeaf:true,draggable:false,items:[]},
						{code:"1004108",name:"燃气",isLeaf:true,draggable:false,items:[]},
						{code:"1004201",name:"可信容量",isLeaf:true,draggable:false,items:[]},
						{code:"10043",name:"线路统计分析",isLeaf:true,draggable:false,items:[]},
						{code:"10044",name:"断面统计分析",isLeaf:true,draggable:false,items:[]},
						{code:"10045",name:"可靠性与电力备用率",isLeaf:true,draggable:false,items:[]},
						{code:"10046",name:"网损统计分析",isLeaf:true,draggable:false,items:[]},
						{code:"1004701",name:"电力平衡详表",isLeaf:true,draggable:false,items:[]},
						{code:"1004702",name:"电力平衡统计表",isLeaf:true,draggable:false,items:[]},
						{code:"1004703",name:"电力平衡日详表",isLeaf:true,draggable:false,items:[]},
						{code:"1004704",name:"电量平衡日详表",isLeaf:true,draggable:false,items:[]},
						{code:"1004801",name:"电量平衡统计表",isLeaf:true,draggable:false,items:[]},
						{code:"1004901",name:"启停台次统计",isLeaf:true,draggable:false,items:[]},
						{code:"1004902",name:"机组利用小时数",isLeaf:true,draggable:false,items:[]},
						{code:"10041002",name:"静态费用详细统计",isLeaf:true,draggable:false,items:[]},
						{code:"100411",name:"技术经济总指标",isLeaf:true,draggable:false,items:[]},
						{code:"10041202",name:"出力特性统计",isLeaf:true,draggable:false,items:[]},
						{code:"10041203",name:"出力概率密度",isLeaf:true,draggable:false,items:[]},
						{code:"10041204",name:"出力累计分布",isLeaf:true,draggable:false,items:[]},
						{code:"10041205",name:"典型出力（模拟值）",isLeaf:true,draggable:false,items:[]},
						{code:"10041206",name:"典型出力（理论值）",isLeaf:true,draggable:false,items:[]},
						{code:"10041302",name:"出力特性统计",isLeaf:true,draggable:false,items:[]},
						{code:"10041303",name:"出力概率密度",isLeaf:true,draggable:false,items:[]},
						{code:"10041304",name:"（光伏）出力累计分布",isLeaf:true,draggable:false,items:[]},
						{code:"10041305",name:"（光伏）典型出力（模拟值）",isLeaf:true,draggable:false,items:[]},
						{code:"10041306",name:"（光伏）典型出力（理论值）",isLeaf:true,draggable:false,items:[]}]
				}
			];
		}
		function  doSave_(){
			
			com.qh.goptcloud.RouteMap.prototype.doSave();
		};
		function getTableData(code, currentPage, pageSize, keyword){
			var defer = $.Deferred();
			var result = null;
			var dateSel =  $('#dateSel').val(); 
			if(JyyCommon.isEmpty(dateSel)){
				JyyMsgBox.alert({ title:"警告", message:"[日期]不可为空",type:"warning"}).on(function (e) {});
				return false;
			}
			dateSel = dateSel.replace('-','');
			dateSel = dateSel.replace('-','');
			$.ajax({
				dataType: "json",
				async:true,
				data:{"pagenow":currentPage,"pagenum":pageSize,"keyword":keyword,"projectid":projectId,"begintime":dateSel},
				url: "page/pageInfo/"+code
			}).done(function(res) {
				var sts=eval("("+res.respData+")");
				result = res;
				defer.resolve(sts);
			});
			return defer.promise();
		}
	</script>
</head>
<body style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;">
	<div id="operate" style="position: absolute;top: 0px;left: 5px;right: 0px;height: 50px;">
		<div class="col-md-12" style="position: absolute;top: 10px;padding-left: 5px;padding-right: 5px;">
			<label  class="control-label col-sm-1" style="float: left;margin-top: 7px;padding: 0px;width: 40px;font-weight: normal;">日期</label>
            <input id="dateSel" class="form-control" placeholder="请选择日期" readonly style="float: left;margin-top: -3px;padding: 5px;width: 184px;font-weight: normal;">

			<button class="selBtn" style="margin-left: 15px;" onclick=select()>查询</button>
			<button id="daochu"  class="selBtn" style="width: 100px;" onclick=download()><i class="glyphicon glyphicon-download"></i>导出Excel</button>
			<!-- <button id="xinzeng" class="btn btn-info btn-sm" onclick=addRow()><i class="fa fa-plus"></i>新增</button>
			<button id="xiugai"  class="btn btn-info btn-sm" onclick=updateRow()><i class="glyphicon glyphicon-pencil"></i>修改</button>
			<button id="quxiao"  class="btn btn-info btn-sm" onclick=cancelRow()><i class="glyphicon glyphicon-share-alt"></i>取消修改</button>
			<button id="shanchu"  class="btn btn-info btn-sm" onclick=deleteRow()><i class="glyphicon glyphicon-remove"></i>删除</button>
			<button id="baocun"  class="btn btn-info btn-sm" onclick=saveRow()><i class="glyphicon glyphicon-saved"></i>保存</button> -->
			
			<!-- <button class="btn btn-info btn-sm" style="float: right;" onclick=reset()>重置</button>
			<button class="btn btn-info btn-sm" style="float: right;margin-right: 5px;" onclick=select()>查询</button>

			<div class="col-sm-3" style="float: right;width:170px;padding-left: 0px;">
            	<input id="term" type="text" class="form-control"style="width:150px;height:30px;font-size: 12px;" id="txt_search_departmentname">
            </div>
			<label id="searchName" class="control-label col-sm-1" style="float: right;margin-top: 7px;padding: 0px;width: 60px;font-weight: normal;" for="txt_search_departmentname"></label>
		 -->
			<input type="file" id="file" name="file" onchange="upload(this)" style="display:none"/>
		</div>
	</div>
	<div id="tree" style="display: none;"></div>
	<div id="table"></div>
	<div id="iframe" style="position: absolute;top: 0px;left: 200px;right: 0px;height: 820px;display:none">
		<iframe  frameborder="0" width="100%" scrolling="No" height="100%" leftmargin="0" topmargin="0" id="sampleIframe"></iframe>
	</div>
	<form action='../pv/page/pageInfo/201' method='post' id='form1' enctype="multipart/form-data">
		<input type="file" id="allDownload" name="allDownload" onchange="allDownloads(this)" style="display:none"/>
		<input type="hidden" name="schemeid">
	</form>
	<form action='../pv/page/pageInfo/202' method='post' id='form2'>
		<input type="hidden" name="schemeid">
	</form>
</body>
</html>